﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.JCI.Common.Entity;
using Microsoft.JCI.Bll;
using Microsoft.JCI.Common.Utility;

namespace Microsoft.JCI.Portal.SysManage
{
    public partial class RoleList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindRoleList(1);
            }
        }

        private void BindRoleList(int pageindex)
        { 
            List<SqlDbParameter> parms = new List<SqlDbParameter>();
            int RecordCount = 0;
            List<SysRoleEntity> list = new SystemBll().GetAll<SysRoleEntity>(parms, "createdon desc", AspNetPager1.PageSize, pageindex, out RecordCount);

            RepeaterRoles.DataSource = list;
            RepeaterRoles.DataBind();
            AspNetPager1.RecordCount = RecordCount;
        }

        protected void RepeaterRoles_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "refersh")
            {
                BindRoleList(1);
            }
        }

        protected void lnkbtnDelete_Click(object sender, EventArgs e)
        {
            if (roleids.Value.Trim() != "") {
                string ids = roleids.Value.Trim();
                string[] idsArray =  ids.Split(new char[] { ';' });
                for (int index = 0; index < idsArray.Length; index++) {
                    SysRoleEntity entity = new SystemBll().Get<SysRoleEntity>(new Guid(idsArray[index]));
                    new SystemBll().LogicDelete(entity);
                    BindRoleList(1);
                }
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {

            BindRoleList(AspNetPager1.CurrentPageIndex);
        }
    }
}
